﻿Namespace Producto.Catalgo


    Public Class frmCatalogoBuscar


        Public Sub LoadParameter()
            'cargarCombo FormaSimple
            CargarFormaSimple()
            CargarFormaCompuesta(Me.cbbFormaSimple.SelectedValue)
            CargarMarca()
            Listar()
        End Sub

        Public Sub CargarMarca()
            Dim obj As New Farmacia.Business.Producto.Marca
            Dim ocol As Farmacia.Entity.Producto.MarcaCol
            ocol = obj.Combo(True)
            Me.cbb_marca.DisplayMember = "Nombre"
            Me.cbb_marca.ValueMember = "MArcaId"
            Me.cbb_marca.DataSource = ocol
        End Sub
        Public Sub CargarFormaSimple()
            Dim obj As New Farmacia.Business.Producto.FormaSimple
            Dim ocol As Farmacia.Entity.Producto.FormaSimpleCol
            ocol = obj.Combo(True)
            Me.cbbFormaSimple.DisplayMember = "Nombre"
            Me.cbbFormaSimple.ValueMember = "FormaSimpleId"
            Me.cbbFormaSimple.DataSource = ocol

        End Sub

        Public Sub CargarFormaCompuesta(ByVal vFormaSimpleId As Integer)
            Dim obj As New Farmacia.Business.Producto.FormaCompuesta
            Dim oCol As Farmacia.Entity.Producto.FormaCompuestaCol
            oCol = obj.Combo(vFormaSimpleId, True)
            Me.cbbFormaCompuesta.DisplayMember = "Nombre"
            Me.cbbFormaCompuesta.ValueMember = "FormaCompuestaID"
            Me.cbbFormaCompuesta.DataSource = oCol
        End Sub


        Public Sub Listar()
            Dim obj As New Farmacia.Business.Producto.Catalogo
            Dim oCOl As Farmacia.Entity.Producto.CatalogoCol
            oCOl = obj.Listar(-1, "", Me.TextBox1.Text, _
                               "", _
                                Me.cbbFormaCompuesta.SelectedValue, _
                                Me.cbbFormaSimple.SelectedValue, _
                                "", _
                                 -1, _
                                  -1, _
                                   "", _
                                   Me.cbb_marca.SelectedValue, _
                                   -1)
            Me.dgw_catalogo.AutoGenerateColumns = True
            Me.dgw_catalogo.DataSource = oCOl


        End Sub


        Private Sub frmCatalogoBuscar_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
            LoadParameter()
        End Sub

        Private Sub cbbFormaSimple_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbbFormaSimple.SelectedIndexChanged
            CargarFormaCompuesta(Me.cbbFormaSimple.SelectedValue)
        End Sub



        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Listar()
        End Sub

        Private Sub btn_AgregarProducto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_AgregarProducto.Click
            AgregarProducto()
        End Sub

        Public Sub AgregarProducto()

            Dim obj As New Farmacia.Business.Producto.Producto
            Dim oCol As Farmacia.Entity.Producto.ProductoCol

            Dim _CatalogoId As Integer = Me.dgw_catalogo.SelectedRows(0).Cells("col_id").Value

            oCol = obj.Listar(-1, -1, _CatalogoId, _
                               -1, -1, "", "", -1, -1, "", "", -1, "", 0, 0, -1, "", "")

            If oCol.Count > 0 Then
                Vichama.Configurations.Aplication.MessageBox.MensajeExclamation2("EL producto ya se encuentra Agregado")
            Else
                'abrir mantenimiento de productos con los valores de Catalogo pre cargados

                Dim frm As New Producto.frmProductoMant
                frm.CatalogoId = _CatalogoId
                If frm.ShowDialog() Then

                End If


            End If
        End Sub

        Private Sub frmCatalogoBuscar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        End Sub
    End Class
End Namespace